<?php
    $link = mysqli_connect("127.0.0.1","root","","h52106");
    $language = mysqli_query($link,"SET NAMES utf8");
    $hide = $_REQUEST["hide"];
    if($hide == "register"){
        $name = $_POST["nc"];
        $pwd = $_POST["mm"];
        $phone = $_POST["sjh"];
        $sql = "SELECT * FROM qquser";
        $indexing = mysqli_query($link,$sql);
        while(($result = mysqli_fetch_assoc($indexing)) != null){
            if($result["name"] == $name){
                echo "<script> sessionStorage.state = '注册失败';location = '../html/qq_status.html'</script>";
                return false;
            }
        }
        $head = "touxiang0.jpg";
        $sql = "INSERT INTO qquser VALUES (0,'$name','$pwd','$phone','','','','','$head','')";
        mysqli_query($link,$sql);
        echo "<script> sessionStorage.state = '注册成功';location = '../html/qq_status.html '</script>";
    }else if($hide == "limitTime"){
        $sql = "SELECT link,name,newprice,oldprice,status FROM jcpgood";
        $rs = mysqli_query($link,$sql);
        $arr = [];
        while(($row = mysqli_fetch_assoc($rs)) != null){
            Array_push($arr,$row);
        }
        // echo JSON_encode($arr);
        echo $_GET["key"]."(".JSON_encode($arr).")";
    }else if($hide == "recommend"){
        $sql = "SELECT link FROM recommend";
        $rs = mysqli_query($link,$sql);
        $arr = [];
        while(($row = mysqli_fetch_assoc($rs)) != null){
            Array_push($arr,$row);
        }
        // echo JSON_encode($arr);
        echo $_GET["key"]."(".JSON_encode($arr).")";
    }else if($hide == "toys"){
        $sql = "SELECT link,name,price FROM toys";
        $rs = mysqli_query($link,$sql);
        $arr = [];
        while(($row = mysqli_fetch_assoc($rs)) != null){
            Array_push($arr,$row);
        }
        // echo JSON_encode($arr);
        echo $_GET["key"]."(".JSON_encode($arr).")";
    }else if($hide == "details"){
        $id = $_GET["id"];
        $sql = "SELECT * FROM jcpgood where id=$id" ;
        $rs = mysqli_query($link,$sql);
        $arr = [];
        while(($row = mysqli_fetch_assoc($rs)) != null){
            Array_push($arr,$row);
        }
        echo $_GET["key"]."(".JSON_encode($arr).")";
    }else if($hide == "login"){
        $name = $_POST["uname"];
        $pwd = $_POST["upwd"];
        $sql = "SELECT id,name,pwd,headphoto FROM qquser";
        $rs = mysqli_query($link,$sql);
        while(($row = mysqli_fetch_assoc($rs)) != null){
            if($row["name"] == $name && $row["pwd"] == $pwd){
                $he = $row["headphoto"];//touxiang.png;
                $uid = $row["id"];
                echo "<script> sessionStorage.uid='{$uid}';localStorage.img='{$he}';sessionStorage.img='{$he}';sessionStorage.state = '登陆成功';localStorage.name='{$name}';sessionStorage.uname='{$name}';location = '../html/qq_status.html'</script>";
                return false;
            }
        }
        echo "<script> sessionStorage.state = '登陆失败';location = '../html/qq_status.html'</script>";
    }else if($hide == "speed"){
        $name = $_GET["name"];
        $img = $_GET["img"];
        $sql = "SELECT id,name,headphoto FROM qquser";
        $rs = mysqli_query($link,$sql);
        while(($row = mysqli_fetch_assoc($rs)) != null){
            if($row["name"] == $name && $row["headphoto"] == $img){
                $he = $row["headphoto"];//touxiang.png;
                $uid = $row["id"];
                echo $_GET["key"]."(".JSON_encode("{$he};{$name};{$uid}").")";
                return false;
            }
        }
        echo "<script> sessionStorage.state = '登陆失败';location = '../html/qq_status.html'</script>";
    }else if($hide == "comment"){
        $gid = $_GET["gid"];
        $sql = "SELECT * FROM comment";
        $rs = mysqli_query($link,$sql);
        $arr = [];
        while(($row = mysqli_fetch_assoc($rs)) != null){
            Array_push($arr,$row);
        }
        echo $_GET["key"]."(".JSON_encode($arr).")";
        // echo $_GET["key"]."(".JSON_encode("{$uid};{$gid}").")";
    }else if($hide == "ifdiscus"){
        $gid = $_GET["gid"];
        $uid = $_GET["uid"];
        $sql = "SELECT * FROM comment";
        $rs = mysqli_query($link,$sql);
        $i = "0";
        while(($row = mysqli_fetch_assoc($rs)) != null){
            if($row["good_id"] == $gid && $row["user_id"] == $uid){
                $i = "1";
            }
        }
        echo $_GET["key"]."(".JSON_encode($i).")";
        // echo $_GET["key"]."(".JSON_encode("{$gid};{$uid}").")";
    }else if($hide == "rewrite"){
        $gid = $_GET["gid"];
        $uid = $_GET["uid"];
        $sql = "SELECT * FROM comment";
        $rs = mysqli_query($link,$sql);
        while(($row = mysqli_fetch_assoc($rs)) != null){
            if($row["good_id"] == $gid && $row["user_id"] == $uid){
                $content = $row["discus"];
                echo $_GET["key"]."(".JSON_encode($content).")";
                return false;
            }
        }
    }else if($hide == "inwrite"){
        echo $_GET["key"]."(".JSON_encode("增加").")";
    }else if($hide == "xiugai"){
        $gid = $_POST["gid"];
        $uid = $_POST["uid"];
        $cont = $_POST["content"];
        $time = $_POST["time"];
        $stars = $_POST["stars"];
        $sql = "SELECT * FROM comment";
        $rs = mysqli_query($link,$sql);
        while(($row = mysqli_fetch_assoc($rs)) != null){
            if($row["good_id"] == $gid && $row["user_id"] == $uid){
                $id = $row["id"];
            }
        }
        $sql = "UPDATE comment SET discus='$cont',dateTime='$time',score='$stars' WHERE id='$id'";
        $rs = mysqli_query($link,$sql);
        if($rs){
            echo "<script> sessionStorage.state = '修改成功';location = '../html/qq_status.html'</script>";
        }else{
            echo $id;
        }
    }else if($hide == "zengjia"){
        $gid = $_POST["gid"];
        $uid = $_POST["uid"];
        $cont = $_POST["content"];
        $time = $_POST["time"];
        $stars = $_POST["stars"];
        $img = $_POST["uimg"];
        $name = $_POST["uname"];
        $sql = "INSERT INTO comment VALUES(0,'$gid','$uid','$cont','$time','$stars','$name','$img')";
        $rs = mysqli_query($link,$sql);
        if($rs){
            echo "<script> sessionStorage.state = '增加成功';location = '../html/qq_status.html'</script>";
        }else{
            echo "<script> sessionStorage.state = '增加失败';location = '../html/qq_status.html'</script>";
        }
    }else if($hide == "updSomeone"){
        $id = $_POST["uid"];
        $name = $_POST["uname"];
        $phone = $_POST["phone"];
        $email = $_POST["email"];
        $img = $_POST["img"];
        $birthday = $_POST["birth"];
        $gender = $_POST["gender"];
        $sql = "UPDATE qquser SET name='$name',phone='$phone',email='$email',headphoto='$img',birthday='$birthday',gender='$gender' WHERE id='$id'";
        $rs = mysqli_query($link,$sql);
        if($rs){
            echo "<script> sessionStorage.state = '修改成功';location = '../html/qq_status.html'</script>";
        }else{
            echo "<script> sessionStorage.state = '修改失败';location = '../html/qq_status.html'</script>";
        }
    }
    //shiyishi
    mysqli_close($link);
?>

